package com.lemner.www.hongyu.Fragement;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lemner.www.hongyu.Adapter.FinishorderAdapter;
import com.lemner.www.hongyu.Bean.FinishorderBean;
import com.lemner.www.hongyu.R;
import com.lemner.www.hongyu.Service.Service;

import java.util.Arrays;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


public class FinishorderFragment extends Fragment {
    private View view;
    private RecyclerView re_finishorder;
    private RecyclerView.LayoutManager layoutManager;
    private FinishorderAdapter adapter;
    private Service service;
    private static String BASEURL="http://www.hongyudasha.com/propertysystem/";
    private Retrofit retrofit;
    private int workerid,ids;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
         view=inflater.inflate(R.layout.fragment_finishorder, container, false);
        Bundle bundle=getArguments();
        workerid=bundle.getInt("workerid",1);
        ids= bundle.getInt("ids",1);
        initRecyclerView();
        getdate();
        return view;
    }
    private void initRecyclerView() {
        re_finishorder = (RecyclerView)view.findViewById(R.id.rv_finishorder);
        //创建默认的线性LayoutManager
        layoutManager = new LinearLayoutManager(getActivity());
        // 设置布局管理器
        re_finishorder.setLayoutManager(layoutManager);
        //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        re_finishorder.setHasFixedSize(true);
        adapter = new FinishorderAdapter(getActivity());
        re_finishorder.setAdapter(adapter);
    }
    //完成订单
    public void getdate(){
        int []id=new int[]{ids};
        final String communityid= Arrays.toString(id);
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        service=retrofit.create(Service.class);
        Call<FinishorderBean>call=service.getComplete(workerid,communityid);
        call.enqueue(new Callback<FinishorderBean>() {
            @Override
            public void onResponse(Call<FinishorderBean> call, Response<FinishorderBean> response) {
                adapter.setBean(response.body().getData());
            }
            @Override
            public void onFailure(Call<FinishorderBean> call, Throwable t) {
                Log.e("error",t.getMessage());
            }
        });

    }



}
